package top.yunmouren.areamusic.commannd;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import top.yunmouren.areamusic.AreaMusic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainTabCompleter implements TabCompleter {
    private final AreaMusic plugin;

    public MainTabCompleter(AreaMusic plugin) {
        this.plugin = plugin;
    }

    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
        if (args.length == 1) {
            List<String> result = new ArrayList();
            List<String> matching = Arrays.asList("music", "area", "reload", "help");

            for (String item : matching) {
                if (item.startsWith(args[0])) {
                    result.add(item);
                }
            }

            return result;
        } else if (args.length == 2) {
            if (args[0].equals("music")) {
                return this.handleSecTab((String[])Arrays.copyOfRange(args, 1, args.length));
            } else {
                return args[0].equals("area") ? this.handleSecTab((String[])Arrays.copyOfRange(args, 1, args.length)) : null;
            }
        } else {
            return null;
        }
    }

    public List<String> handleSecTab(String[] args) {
        List<String> tabStr = new <String>ArrayList();
        List<String> matching = Arrays.asList("add", "list", "del");

        for (String item : matching) {
            if (item.startsWith(args[0])) {
                tabStr.add(item);
            }
        }

        return tabStr;
    }
}